package array;

public class Test1 {
    public static void main(String[] args) {
    //目标：创建一个扑克牌的数组并洗牌打乱的方法
        getPoker();
    }

    public static void getPoker(){
        //1.创建一个扑克牌的动态数组
        String[] poker = new String[54];

        //2.创建一个花色的数组
        String[] colors = {"♠","♥","♣","♦"};
        String[] numbers = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};

        //3.遍历数组，将数组中的元素赋值给poker数组
        int index = 0;//索引值
        for (int i = 0; i < colors.length; i++) {
            for (int j = 0; j < numbers.length; j++) {
                poker[index++] = numbers[j] + colors[i];
            }
        }

        //添加大小王
        poker[index++] = "BJ";
        poker[index]   = "SJ";

        //4.打印洗牌前扑克牌
        System.out.println("洗牌前：");
        for (int i = 0; i < poker.length ; i++) {
            System.out.print(poker[i] + "\t"); //\t是制表符
        }
        System.out.println();

        //5.洗牌打乱
        for (int i = 0; i < poker.length; i++) {

            int index1 = (int)(Math.random() * poker.length);//随机索引1
            int index2 = (int)(Math.random() * poker.length);//随机索引2

            //交换
            String temp = poker[index1];
            poker[index1] = poker[index2];
            poker[index2] = temp;
        }

        //6.打印洗牌后扑克牌
        System.out.println("洗牌后：");
        for (int i = 0; i < poker.length ; i++) {
            System.out.print(poker[i] + "\t"); //print 加 ln 是换行打印
        }
        System.out.println();
    }
}
